home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / dos_win / winsock / maillist / 94-05.Z / 94-05 / text0092.txt < prev    next >
Encoding:
Text File  |  1994-05-31  |  2.2 KB  |  67 lines

  1. On Thu, 5 May 1994, Chris Rowley wrote:
  2.  
  3. > >        I am no expert by any means but is it possible to write everything in 
  4. > >Visual Basic? <:-) (maybe a dumb question) Can the interface to winsock (VBX) 
  5. > >be written in VB itself?
  6. > Hi Paul,
  7. >    As visual basic stands, it looks like the answer in no. The hostent data 
  8. > structure (which is used for such, oh, noteworthy functions like 
  9. > gethostbyname, cannot be realized in VB because it contains lists of lists. 
  10.  
  11. At the risk of sounding like a zealot, I think that ALMOST ANYTHING to do 
  12. with WINSOCK can be written in VB.  I have done a basic set of routines 
  13. in VB calling the WINSOCL DLL directly - these worked in blocking mode, 
  14. and I am currently porting them to work in async mode - this would be 
  15. impossible except for the wonderful MSGBLAST.VBX (public domain from 
  16. Microsoft).  Meanwhile, to call the blocking "get host by name", use 
  17. something like this fragment:
  18.  
  19. Type hostent
  20.     h_name_addr As Long
  21.     h_aliases_ptr_addr As Long
  22.     h_addrtype As Integer
  23.     h_length As Integer
  24.     h_addr_list_ptr_addr As Long
  25. End Type
  26.  
  27. Declare Function gethostbyname Lib "winsock.dll" (ByVal hostname As
  28. String) As Long
  29. Declare Sub hmemcpy Lib "Kernel" (dest As Any, src As Any, ByVal n As Long)
  30.  
  31. Function TCPHostLookup (host$) As Long
  32.  
  33.  
  34.     Dim thishost As hostent
  35.     Dim hostptr As Long
  36.     Dim addrp As Long
  37.     Dim addr1 As Long
  38.  TCPHostLookup = 0   ' assume the werst
  39.  
  40.     hostptr = gethostbyname(ByVal host$)
  41.     If hostptr = 0 Then
  42.  
  43.        Debug.Print "lookerr:" & TCPGetErrorMsg()
  44.     Else
  45.         Debug.Print "hostptr="; hostptr
  46.         hmemcpy thishost, ByVal hostptr, 16
  47.         hmemcpy addrp, ByVal thishost.h_addr_list_ptr_addr, 4
  48.         Debug.Print "addrp=", addrp
  49.         If addrp <> 0 Then
  50.             hmemcpy addr1, ByVal addrp, 4
  51.             Debug.Print "final addr=", addr1
  52.             TCPHostLookup = addr1   ' the jackpot
  53.         End If
  54.     End If
  55. End Function
  56.  
  57. Note: TCPGetErrorMsg() just gets the last WS error and decodes into English
  58.  
  59. Goodluck
  60.  
  61. Kent Fitch                           Ph: +61 6 276 6711
  62. ITSB   CSIRO  Canberra  Australia    kent.fitch@its.csiro.au
  63. "We dare not trust our wit for making our house pleasant for our friends,
  64.  so we buy ice-cream"     -  Ralph Waldo Emerson
  65.  
  66.